package net.nightwhistler.pageturner.view.bookview;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.shwread.android.qysw10000243.R;

import net.nightwhistler.htmlspanner.FontFamily;
import net.nightwhistler.pageturner.view.FastBitmapDrawable;


public class CoverChapterView extends RelativeLayout {

	TextView txtTitle;
	TextView txtSubTitle;
	ImageView imgBackground;
	FastBitmapDrawable cover;

	public CoverChapterView(Context context, AttributeSet attrs) {
		super(context, attrs);

		// 设定View
		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		inflater.inflate(R.layout.epub3_view_cover_chapter, this);
		txtTitle = (TextView) this.findViewById(R.id.txtCoverTitle);
		txtSubTitle = (TextView) this.findViewById(R.id.txtCoverSubTitle);
		imgBackground = (ImageView) this.findViewById(R.id.imgCoverChapter);
	}

	public void UpdateUI(String title, String subTitle) {
		txtTitle.setText(title);
		txtSubTitle.setText(subTitle);
	}

	public void setCoverImage(FastBitmapDrawable cover) {
		this.cover = cover;
		this.imgBackground.setImageDrawable(cover);
	}

	public void clear() {
		if (this.cover != null) {
			this.cover.destroy();
		}
	}

	public void clearImage() {
		clear();
		this.cover = null;
		this.imgBackground.setImageDrawable(null);
	}

	public void SetTextType_Color(int color, FontFamily fm) {
		this.txtSubTitle.setTextColor(color);
		this.txtTitle.setTextColor(color);

		this.txtSubTitle.setTypeface(fm.getDefaultTypeface());
		this.txtTitle.setTypeface(fm.getDefaultTypeface());
	}
}
